
// const winWidth = window.innerWidth;
// console.log(winWidth);
// if(winWidth<990){
//     Left.style.display = 'none';
//     // alert("你可以尝试将窗口最大化，或者再pc端登录继续进行面试")
//     // location.href="../admin/index"
//     // qu("#left").classList.remove("layui-col-md2")
//     // qu("#left").classList.add("layui-col-md1")
//     // qu("#right").classList.remove("layui-col-md10")
//     // qu("#right").classList.add("layui-col-md11")
// }

// 引入layui表单模块
var flagSubmit = 0; //判断是否点击过，
layui.use('form', function(){
    var form = layui.form;
    //监听提交
    form.on('submit(formDemo)', function(data){
      layer.msg(JSON.stringify(data.field));
    //   console.log(data.field);
      return false;
    });
  });
// 查找用户id
function findId(){
    // console.log("---------");
    // console.log(document.querySelector(".admin").getAttribute("name"));
    axios({
        url:"/admin/interview/findId",
        method:"GET",
        params: {
            name:document.querySelector(".admin").getAttribute("name")
        }
        }).then(data=>{
            // console.log(data.data.data.id);
            userId.value=data.id
        });
}
findId();
//   渲染题库
var length=10;
var question_wrap = qu("#question_wrap")
function questionsFun(){
    // findByInterview
    axios({
        url:"/admin/interview/findByInterview",
        method:"GET",
        }).then(data=>{
            // console.log(data.data);
            length=data.data.length;
            // question_wrap.style.width=500*data.data.length+"px"
            // for(let i=0;i<data.data.length;i++){
            //     question_wrap.innerHTML+=`
            //     <div class="per_question">
            //                 <div class="per_top">
            //                     <span>${i+1}/${data.data.length}</span>
                                
            //                     <span id="closeWin" onclick="closeWinFun()">X</span>
            //                 </div>
            //                 <hr>
            //                 <div class="per_wrap">
            //                     <p>${data.data[i].quessionName}</p>
            //                 </div>
            //     </div>
            //     `
            // }
           
            for(let i=0;i<data.data.length;i++){
                     qu('.questionsDiv').innerHTML+=`
                     <p> <b>${i+1}、</b> ${data.data[i].quessionName}</p>
                     <hr>
                    `
            }
        });
    
}
questionsFun();
var page=1;

function prevFun(){
    if(page>1){
        page--;
        question_wrap.style.left=-(page-1)*500+"px"
    }
}
function nextFun(){
    if(page<length){
        page++;
        question_wrap.style.left=-(page-1)*500+"px"
    }
}
function closeWinFun(){
    coverWindow.style.display="none";
    questionWin.style.display="none";
    submitWin.style.display="none";
    bigImg.style.display="none";
}
function openQuestionWinFUn(){
    coverWindow.style.display="block";
    questionWin.style.display="block";
}

var flag = false;
var flagScore = false;
// console.log(userId.value);
$('#scoreForm').on('submit',function(){
    if (flag==true){
        alert('辛苦了，面试结果已提交😊')
        location.href="index"
        return false;
    }
    var result = serializeToJson($(this))
    // console.log(result.desc==0);
    // console.log('attitude' in result);
    if (result.desc==0) {
        // alert("清填写意见看法")      
        flagScore = true;
        
        cover_div.style.display="block"
        windowDiv.style.display="block"  
    }else if('attitude' in result==false) {
        // alert("态度还未打分");
        flagScore = true;
        endFun()
    }else if('communicate' in result==false) {
        // alert("沟通能力还未打分");
        flagScore = true;
        endFun()
    }else if('compression' in result==false) {
        // alert("抗压能力还未打分");
        flagScore = true;
        endFun()
    }else if('heart' in result==false) {
        // alert("心理素质还未打分");
        flagScore = true;
        endFun()
    }else if('strain' in result==false) {
        // alert("应变能力还未打分");
        flagScore = true;
        endFun()
    }else if('study' in result==false) {
        // alert("自学能力还未打分");
        flagScore = true;
        endFun()
    }else if('understand' in result==false) {
        // alert("对小组了解情况还未打分");
        flagScore = true;
        endFun()
    }else{
        // flag=true;
        flagScore = false;
        // wrapCover_three.style.display="block";
        // resetBtn.style.display="none";
            submitWin.style.display="block";
            if (state.value=="待三面") {
                nextBtn.style.display="none";
            }
            coverWindow.style.display="block";
    }
   
    return false;
})
function returnFun(){
    location.href="index"
}
function findCommon(){
    // console.log(interviewersId.value);
    // console.log(state.value);
    if(state.value=="待面试"||state.value=="待一面"){
        wrap_two.style.display="none";
        title_three.innerHTML="二、面试打分"
    }else if(state.value=="待三面"){
        wrap_three.style.display="none";
        wrap_four.style.display="block";
        axios({
            url:"/admin/interview/findCommen",
            method:"GET",
            params:{
                interviewersId :interviewersId.value,
                state: state.value,
            }
            }).then(data=>{
                // console.log(data.data);
                tybody.innerHTML=''
                for(let i=0;i<data.data.length;i++){
                    tybody.innerHTML+=`
                    <tr>
                    <td class="commen_td">${data.data[i].username}</td>
                    <td>${data.data[i].content}</td>
                    <td class="commen_td">
                        ${data.data[i].state}
                    </td>
                </tr>
                    `
                }
                if(data.data.length==0){
                    tybody.innerHTML+=`
                    <tr>
                        <td class="commen_td"> </td>
                        <td>暂无面试官评论</td>
                        <td class="commen_td">
                            
                        </td>
                    </tr>
                    `
                }
                
            });
    }else{
        axios({
            url:"/admin/interview/findCommen",
            method:"GET",
            params:{
                interviewersId :interviewersId.value,
                state: state.value,
            }
            }).then(data=>{
                // console.log(data.data);
                tybody.innerHTML=''
                for(let i=0;i<data.data.length;i++){
                    tybody.innerHTML+=`
                    <tr>
                    <td class="commen_td">${data.data[i].username}</td>
                    <td>${data.data[i].content}</td>
                    <td class="commen_td">
                        ${data.data[i].state}
                    </td>
                </tr>
                    `
                }
                if(data.data.length==0){
                    tybody.innerHTML+=`
                    <tr>
                        <td class="commen_td">无评论</td>
                        <td>暂无面试官评论</td>
                        <td class="commen_td">
                           一面
                        </td>
                    </tr>
                    `
                }
                
            });
    }
    
}
findCommon();
function findScore(){
    return new Promise((resolve, reject) => {
        /* 你的逻辑代码 */
         // console.log(interviewersId.value)
        // console.log("1");
            axios({
                url:"/admin/interview/findScore",
                method:"GET",
                params:{
                    interviewersId :interviewersId.value,
                    value: "一面",
                }
                }).then(data=>{
                    resolve(data.data)
                    // console.log("01:"+data.data);
                    
                    
                });
    });
   
}
 function getScore_two(){
    // awite findScore()
    return new Promise((resolve, reject) => {
        /* 你的逻辑代码 */
        // console.log("2");
            axios({
                url:"/admin/interview/findScore",
                method:"GET",
                params:{
                    interviewersId :interviewersId.value,
                    value: "二面",
                }
                }).then(data=>{
                    resolve(data.data)
                    
                })
    });
}
function findAverageScore(){
    return new Promise((resolve, reject) => {
        /* 你的逻辑代码 */
        // console.log("3");
        axios({
            url:"/admin/interview/findAverageScore",
            method:"GET",
            params:{
                interviewersId :interviewersId.value,
                state: "一面",
            }
            }).then(data=>{
                resolve(data.data[0]);
                
                
            });
    });
    
}
function findAverageScore_two(){
    return new Promise((resolve, reject) => {
        /* 你的逻辑代码 */
        // console.log("4");
        axios({
            url:"/admin/interview/findAverageScore",
            method:"GET",       
            params:{
                interviewersId :interviewersId.value,
                state: "二面",
            }
            }).then(data=>{
                resolve(data.data[0]);
            });
    });
    
}
async function fun(){
    let a =await findScore()
    let b =await getScore_two()
    let c=await findAverageScore()
    let d =await findAverageScore_two()
    tybody_score.innerHTML=''
    console.log(state.value);
    if(state.value =="待三面"){
        for(let i=0;i<a.length;i++){
            tybody_score.innerHTML+=`
            <tr>
                <td >${a[i].username?a[i].username:"姓名"}</td>
                <td>${a[i].attitude}</td>   
                <td>${a[i].communicate}</td>
                <td>${a[i].compression}</td>
                <td>${a[i].heart}</td>
                <td>${a[i].strain}</td>
                <td>${a[i].study}</td>
                <td>${a[i].understand}</td>
                <td>${a[i].sum}</td>
                <td>${a[i].value}</td>
            </tr>
                `
            }
        if(a.length==0){
            tybody_score.innerHTML+=`
            <tr>
                <td >无人打分</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>一面</td>
            </tr>
                `
        }  
        for(let i=0;i<b.length;i++){
            tybody_score.innerHTML+=`
            <tr>
                <td>${b[i].username?b[i].username:"姓名"}</td>
                <td>${b[i].attitude}</td>
                <td>${b[i].communicate}</td>
                <td>${b[i].compression}</td>
                <td>${b[i].heart}</td>
                <td>${b[i].strain}</td>
                <td>${b[i].study}</td>
                <td>${b[i].understand}</td>
                <td>${b[i].sum}</td>
                <td>${b[i].value}</td>
            </tr>
        `
        }
        if(b.length==0){
            tybody_score.innerHTML+=`
            <tr>
                <td >无人打分</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
                <td>二面</td>
            </tr>
                `
        }   
        if(a.length!=0){
        tybody_score.innerHTML+=`
        <tr>
            <td >一面平均分</td>
            <td>${c[5]==null?0:c[5]}</td>
            <td>${c[1]==null?0:c[1]}</td>
            <td>${c[4]==null?0:c[4]}</td>
            <td>${c[0]==null?0:c[0]}</td>
            <td>${c[2]==null?0:c[2]}</td>
            <td>${c[3]==null?0:c[3]}</td>
            <td>${c[6]==null?0:c[6]}</td>
            <td>${c[7]==null?0:c[7]}</td>
            <td>一面</td>
            </tr>
        `  
        }
        if(b.length!=0){
            tybody_score.innerHTML+=`
            <tr>
            <td >二面平均分</td>
            <td>${d[5]==null?0:d[5]}</td>
            <td>${d[1]==null?0:d[1]}</td>
            <td>${d[4]==null?0:d[4]}</td>
            <td>${d[0]==null?0:d[0]}</td>
            <td>${d[2]==null?0:d[2]}</td>
            <td>${d[3]==null?0:d[3]}</td>
            <td>${d[6]==null?0:d[6]}</td>
            <td>${d[7]==null?0:d[7]}</td>
            <td>二面</td>
        </tr>
        `  
        }
        // if(a.length==0 && b.length==0){
        //     wrap_two.innerHTML=''
        //     wrap_two.innerHTML=`
        //     <h1>二、面试官看法</h1>
        //     <h5 style="text-align: center;">暂无面试官看法</h5>
        //     `
        // }
        console.log("2");
    }else{
        for(let i=0;i<a.length;i++){
            tybody_score.innerHTML+=`
            <tr>
            <td >${a[i].username?a[i].username:"姓名"}</td>
            <td>${a[i].attitude}</td>
                    <td>${a[i].communicate}</td>
                    <td>${a[i].compression}</td>
                    <td>${a[i].heart}</td>
                    <td>${a[i].strain}</td>
                    <td>${a[i].study}</td>
                    <td>${a[i].understand}</td>
                    <td>${a[i].sum}</td>
                    <td>${a[i].value}</td>
                    
                    </tr>
                `
            }
            if(a.length==0){
                tybody_score.innerHTML+=`
                <tr>
                    <td >无人打分</td>
                    <td>0</td>
                    <td>0</td>
                    <td>0</td>
                    <td>0</td>
                    <td>0</td>
                    <td>0</td>
                    <td>0</td>
                    <td>0</td>
                    <td>一面</td>
                </tr>
                    `
            }
            if(a.length !=0){
                tybody_score.innerHTML+=`
                <tr>
                    <td >一面平均分</td>
                    <td>${c[5]==null?0:c[5]}</td>
                    <td>${c[1]==null?0:c[1]}</td>
                    <td>${c[4]==null?0:c[4]}</td>
                    <td>${c[0]==null?0:c[0]}</td>
                    <td>${c[2]==null?0:c[2]}</td>
                    <td>${c[3]==null?0:c[3]}</td>
                    <td>${c[6]==null?0:c[6]}</td>
                    <td>${c[7]==null?0:c[7]}</td>
                    <td>一面</td>
                    </tr>
                `   
            }   
           
    console.log("3");
        // if(a.length==0){
        //     wrap_two.innerHTML=''
        //     wrap_two.innerHTML+=`
        //     <h1>二、面试官看法</h1>
        //     <h5 style="text-align: center;">暂无面试官看法</h5>
        //     `
        // }
    }
}
if(state.value=="待三面"||state.value=="待二面"){
    fun()
}
// fun()
// findAverageScore()
var studentId = qu(".studentId")
function submitFun(e){
    this.disabled = true;
    console.log(flagSubmit);
    if(flagSubmit == 0){
        e=e || window.event;
        var target=e.target || e.srcElement;
        axios({
            url:"/admin/interview/getState",
            method:"GET",
            params:{
                id :studentId.getAttribute("name"),
            }
            }).then(data=>{
                if(data.data.data.state==state.value){
                    checkState=0;
                    submitSocres();
                    ChangeStateFun(target.getAttribute("name"),studentId.getAttribute("name"));
                    initTimePlaceFun();
                }else{
                    if(flagScore == false){
                        submitSocres();
                    }
                    alert("检测到当前面试者已有其他面试官对其修改，辛苦了")
                    setTimeout(function(){
                        location.href="index"
                    },3000)
                }
                flagSubmit = 1;
            });
    }
    
       
}
function endFun(){
    
    submitWin.style.display="block";
    if (state.value=="待三面") {
        nextBtn.style.display="none";
    }
    coverWindow.style.display="block";
}
function ChangeStateFun(state,studentId){
    initTimePlaceFun(studentId);
    saveInterviews_a(document.getElementById("Left_Two").getAttribute('name'))
    axios({
        url:'/admin/index/changeState',
        method:'GET',
        params: {
            state: state,
            studentId: studentId
        }
    }).then(data => {
        location.href="index"
    })
}
function submitSocres(){
    var scoreForm = document.getElementById('scoreForm');
    var result = serializeToJson($(scoreForm))
    console.log(result);
    axios({
        url:"/admin/interview/grade",
        method:"GET",
        params:{
            attitude:result.attitude,
            communicate:result.communicate,
            compression: result.compression,
            desc: result.desc,
            heart:result.heart,
            interviewersId:result.interviewersId,
            state: result.state,
            strain: result.strain,
            study: result.study,
            understand: result.understand,
            userid:document.querySelector(".admin").getAttribute("name") 

        }
        }).then(data=>{
            // console.log("193:"+data.data);
            
        });
    axios({
        url:"/admin/interview/addCommen",
        method:"GET",
        params:{
            interviewersId:interviewersId.value,
            desc: result.desc,
            state: result.state,
            userid:document.querySelector(".admin").getAttribute("name") 

        }
        }).then(data=>{
            // console.log(data.data);
        });
}
function imgFun(e){
    current = 270;
    rolateFun();
    e=e || window.event;
    var target=e.target || e.srcElement;
    console.log(target.getAttribute("src"));
    if(target.getAttribute("src")=="未上传简历"){
        layui.use("layer",function(){
            layer.msg('简历未上传', {
                icon: 7,
                time: 2000
            })
        })
    }else{
        bigImg.setAttribute("src",target.getAttribute("src"))
        bigImg.style.display="block";
        coverWindow.style.display="block"
    }
}
// function initTimePlaceFun(){
//     axios({
//         url:'/admin/tables/setPlaceAndTime',
//         method:'POST',
//         params: {
//             id: studentId,
//             time:"未设置",
//             place:"未设置"
//         }
//     }).then(data => {
//         alert("变更成功");
//         location.href="index"
//     })
// }

function cancleDelFun(){
    cover_div.style.display="none"
    windowDiv.style.display="none"
}
function submitDelFun(){
    cover_div.style.display="none"
    windowDiv.style.display="none"
    // wrapCover_three.style.display="block";
    // resetBtn.style.display="none";
    // flag=true;
    submitWin.style.display="block";
    // nextBtn.style.display="none";
    coverWindow.style.display="block";
}
(function(){
    var imgs = document.getElementsByClassName('imgs');
    if(imgs[0].getAttribute("name")=='未上传简历'){
        // console.log(123);
        imgs[0].innerHTML = '';
        imgs[0].innerHTML +='简历正面未上传'
    }
    if(imgs[1].getAttribute("name")=='未上传简历'){
        // console.log(123);
        imgs[1].innerHTML = '';
        imgs[1].innerHTML +='简历反面未上传'
    }
    imgs[0].onclick=function(){
        if(this.getAttribute("name")=='未上传简历'){
            layui.use("layer",function(){
                layer.msg('简历正面未上传', {
                    icon: 7,
                    time: 2000
                })
            })
        }
    }
    imgs[1].onclick = function(){
        if(this.getAttribute("name")=='未上传简历'){
            layui.use("layer",function(){
                layer.msg('简历反面未上传', {
                    icon: 7,
                    time: 2000
                })
            })
        }
    }
})()

let wrapCover_three = qu('#wrapCover_three');
wrapCover_three.onclick = function () {
    layui.use("layer",function(){
        layer.msg('您的建议和打分已提交，如需更改可有尝试刷新页面', {
            icon: 7,
            time: 2000
        })
    })
}
var bigImg = qu('#bigImg');
var current = 0;
function rolateFun(){
    // $("#bigImg").rotate(90*num)
    current = (current+90)%360;
    bigImg.style.transform = 'rotate('+current+'deg)';
    // bigImg.style.margin = '0 0 0 0';
    // bigImg.setAttribute('left','0 !important')
    // num++;
}